package be.jhd.domain;

import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

public class SpringValidationResponse extends ValidationResponse{

	public static ValidationResponse getInstance(BindingResult result) {
		final SpringValidationResponse response = new SpringValidationResponse();
		for(FieldError error : result.getFieldErrors()){
			response.addErrorMessage(error);
		}
		return response;
	}
	
	protected void addErrorMessage(FieldError error) {
		addErrorMessage(error.getField(), error.getDefaultMessage());
	}
}
